#include "TestRadioButtonForm.h"



TestRadioButtonForm::TestRadioButtonForm() : m_btnPushLike(1), m_btnAutoSelect(2), m_radioButton1(3), m_radioButton2(4) {

	this->CreatedEvent.Register(this, &TestRadioButtonForm::OnCreated);

	this->SetSize(400, 300);
}



void TestRadioButtonForm::OnCreated(CreatedEventArgs&) {

	m_btnPushLike.SetSize(100, 35);
	m_btnPushLike.SetPosition(0, 0);
	m_btnPushLike.SetText(L"Push like");
	m_btnPushLike.SetParent(*this);
	m_btnPushLike.Create();

	m_btnAutoSelect.SetSize(100, 35);
	m_btnAutoSelect.SetPosition(100, 0);
	m_btnAutoSelect.SetText(L"Auto select");
	m_btnAutoSelect.SetParent(*this);
	m_btnAutoSelect.Create();

	m_radioButton1.SetPosition(100, 50);
	m_radioButton1.SetSize(100, 35);
	m_radioButton1.SetText(L"Choice1");
	m_radioButton1.SetParent(*this);
	m_radioButton1.Create();

	m_radioButton2.SetPosition(200, 50);
	m_radioButton2.SetSize(100, 35);
	m_radioButton2.SetText(L"Choice2");
	m_radioButton2.SetParent(*this);
	m_radioButton2.Create();

	m_labSelected.SetPosition(0, 90);
	m_labSelected.SetSize(200, 35);
	m_labSelected.SetText(L"No radiobutton selected.");
	m_labSelected.SetParent(*this);
	m_labSelected.Create();
}



LRESULT TestRadioButtonForm::WndProc(const WndMsg& msg) {

	if (msg.Message == WM_COMMAND) {

		if (msg.WParamHigh == BN_CLICKED) {

			if (msg.WParamLow == m_btnPushLike.GetID()) {

				m_radioButton1.IsPushLike( ! m_radioButton1.IsPushLike());
			}
			else if (msg.WParamLow == m_btnAutoSelect.GetID()) {
				
				m_radioButton1.IsAutoSelect( ! m_radioButton1.IsAutoSelect());
			}
			else if (msg.WParamLow == m_radioButton1.GetID()) {

				if (m_radioButton1.IsSelected() == true) {
					m_labSelected.SetText(L"RadioButton1 selected.");
				}
			}
			else if (msg.WParamLow == m_radioButton2.GetID()) {

				if (m_radioButton2.IsSelected() == true) {
					m_labSelected.SetText(L"RadioButton2 selected.");
				}
			}
		}
	}

	return Form::WndProc(msg);
}